﻿using Microsoft.AspNetCore.Identity;
using Shop.Application.UserAdmin.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Application.UserAdmin
{
    public class CreateUser
    {
        private UserManager<IdentityUser> _userManager;

        public CreateUser(UserManager<IdentityUser> userManager)
        {
            _userManager = userManager;
        }

        public async Task<bool> Do(UserInput input)
        {
            try
            {
                var mangerUser = new IdentityUser()
                {
                    UserName = input.Name
                };

                await _userManager.CreateAsync(mangerUser,input.PassWord);
                var mangerClaim = new Claim("Role", "Manger");
                await _userManager.AddClaimAsync(mangerUser, mangerClaim);

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
